package com.ruoyi.web.controller.disasterAssessment;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.disasterassessment.domain.DisasterAssessmentModel;
import com.ruoyi.disasterassessment.service.IDisasterAssessmentModelService;
import com.ruoyi.disasterassessment.vo.DisasterAssessmentModelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 安全评估模型Controller
 * 
 * @author hcc
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/disasterassessment/assessmentModel")
public class DisasterAssessmentModelController extends BaseController
{
    @Autowired
    private IDisasterAssessmentModelService disasterAssessmentModelService;

    /**
     * 查询安全评估模型列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(DisasterAssessmentModel disasterAssessmentModel)
    {
        startPage();
        List<DisasterAssessmentModel> list = disasterAssessmentModelService.selectDisasterAssessmentModelList(disasterAssessmentModel);
        return getDataTable(list);
    }

    /**
     * 导出安全评估模型列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:export')")
    @Log(title = "安全评估模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DisasterAssessmentModel disasterAssessmentModel)
    {
        List<DisasterAssessmentModel> list = disasterAssessmentModelService.selectDisasterAssessmentModelList(disasterAssessmentModel);
        ExcelUtil<DisasterAssessmentModel> util = new ExcelUtil<DisasterAssessmentModel>(DisasterAssessmentModel.class);
        util.exportExcel(response, list, "安全评估模型数据");
    }

    /**
     * 获取安全评估模型详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(disasterAssessmentModelService.selectDisasterAssessmentModelById(id));
    }

    /**
     * 新增安全评估模型
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:add')")
    @Log(title = "安全评估模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DisasterAssessmentModel disasterAssessmentModel)
    {
        return toAjax(disasterAssessmentModelService.insertDisasterAssessmentModel(disasterAssessmentModel));
    }

    /**
     * 修改安全评估模型
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:edit')")
    @Log(title = "安全评估模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DisasterAssessmentModel disasterAssessmentModel)
    {
        return toAjax(disasterAssessmentModelService.updateDisasterAssessmentModel(disasterAssessmentModel));
    }

    /**
     * 删除安全评估模型
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:remove')")
    @Log(title = "安全评估模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(disasterAssessmentModelService.deleteDisasterAssessmentModelByIds(ids));
    }
    /**
     * 查询安全评估模型列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessmentModel:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(@RequestBody DisasterAssessmentModelVo vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<DisasterAssessmentModel> list = disasterAssessmentModelService.selectDisasterAssessmentModelList(vo);
        return getDataTable(list);
    }
}
